<?php
/*
 * 用户验证
*/
namespace App\Validation;

use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Numericality;

class UserValidation extends BaseValidation
{
    public function initialize()
    {
		$sub = $this->session->get('sub');
		$nickname_params = ["message" => "The nickname is required"];
		if(!empty($sub->nickname)){
			$nickname_params['allowEmpty'] = true;
		}
		$this->add(
			"nickname",
			new PresenceOf(
				$nickname_params  
			)
		);
		
		$this->add(
			"address",
			new PresenceOf(
				  [
					  "message" => "The address is required",
					  "allowEmpty" => true,
				  ]
			)
		);
		
		$this->add(
			"sex",
			new PresenceOf(
				  [
					  "message" => "The sex is required",
					  "allowEmpty" => true,
				  ]
			)
		);

		$this->add(
			"sign",
			new PresenceOf(
				  [
					  "message" => "The sign is required",
					  "allowEmpty" => true,
				  ]
			)
		);
        $this->add(
            "account",
            new PresenceOf(
                [
                    "message" => "The address is required",
                    "allowEmpty" => true,
                ]
            )
        );
        $this->add(
            "pwd",
            new PresenceOf(
                [
                    "message" => "The address is required",
                    "allowEmpty" => true,
                ]
            )
        );
        $this->add(
            "role_id",
            new PresenceOf(
                [
                    "message" => "The address is required",
                    "allowEmpty" => true,
                ]
            )
        );
        $this->add(
            "mobile",
            new PresenceOf(
                [
                    "message" => "The address is required",
                    "allowEmpty" => true,
                ]
            )
        );
        $this->add(
            "last_login_time",
            new PresenceOf(
                [
                    "message" => "The address is required",
                    "allowEmpty" => true,
                ]
            )
        );
    }
	
	//验证之前
	public function beforeValidation($data, $entity, $messages)
    {
    	
        return true;
    }
	
}